-
Notifications
You must be signed in to change notification settings - Fork 13.3k
User-defined placement-box #18233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User-defined placement-box #18233
Conversation
Note that this narrows desugaring to only be when actual placer is provided; `box <value_expr>` and `box () <value_expr>` both still fall through to the `mk_unary(UnUniq, _)` path. Many more compile-fail tests would need updating if we were not restricting desugaring to `box` with explicit placer.
agh failed (okay, fixed now; earlier review request still stands. :) |
(on reflection, I'm not sure why I thought printing from drop would be any better than failing from drop. I will revise those to just call |
ExchangeHeapSingleton { _force_singleton: () }; | ||
|
||
/// This the singleton type used solely for `boxed::HEAP`. | ||
pub struct ExchangeHeapSingleton { _force_singleton: () } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term exchange heap really shouldn't be used. It's not how dynamic allocation works in Rust. It's wrong to refer to this as HEAP
at all. The Box<T>
type represents a dynamic allocation from the same allocator as other types like Vec<T>
and Rc<T>
. Rust doesn't draw any distinction between memory on a "heap" and other memory mappings.
The |
There needs to be a clear plan on how this is going to work for use cases like vector or hash table inserts before I'm comfortable with it, because I don't want to see Rust end up with an inadequate language feature that needs to be duplicated. |
@thestinger Good point, that is an important use case. I don't see any trouble expressing something like |
If it can support |
This made some things cleaner (e.g. I got to get rid of the `Cell` in the `AtomPool` example). But it also highlights some weaknesses in my current expansion -- namely, my use of top-level functions rather than methods means that I am currently forced to make sure I have the right level of borrowing in the PLACER input in `box (PLACER) EXPR`. I will look into my options there -- it may be that the right thing is just to switch to method invocations.
/// the fact that the `align_of` intrinsic currently requires the | ||
/// input type to be Sized (which I do not think is strictly | ||
/// necessary). | ||
pub struct IntermediateBox<Sized? T>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is public, we'll be committing to the continued existence of this type, at least. I'm ok with this but cc @aturon. We'll probably want to bikeshed the name :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Of course there's no way to avoid having this be public, at least not without private trait methods at the very least...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular I expect we want to reuse the "agent" term
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Thu, Nov 06, 2014 at 07:48:41AM -0800, Felix S Klock II wrote:
(Of course there's no way to avoid having this be public, at least not without private trait methods at the very least...)
Yes. And I think that's ok.
// implement the Placer trait. Likewise, the actual | ||
// expansion below actually calls free functions in | ||
// `std::ops::placer`, in order to avoid the need for UFCS | ||
// (and also to hopefully produce better error messags). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just using Placer::place(&mut <place_expr>)
and so on will have a similar effect
It probably makes sense to leave these for follow-up PRs, but it'd be nice to have placer implementations for:
We should perhaps make a tracker issue (after this lands) for those sorts of things. Not a huge deal as they can be added as we like. |
(added link to Proto RFC on discuss to the description; you can see it here: http://discuss.rust-lang.org/t/pre-rfc-placement-box-with-placer-trait/729/5 ) |
This needs a rebase. |
(closing; I no longer think this is on the 1.0 timeframe) |
see #22086 |
Add support for user-defined placement-box expressions (i.e.
box (<place>) <value>
for types other thanBox<T>
).This is a prototype design that @nikomatsakis and @pnkfelix have been working on. It works by desugaring an instance of placement-box into a protocol where we first create the intermediate storage with a pseudo-out-pointer, then initialize the storage, and then convert the out-pointer into the desired box type.
The code was originally written to handle both
box (<place>) <value>
andbox <value>
via the same uniform desugaring, and it is easy to revise support for the latter; but as is, this PR only putsbox (<place>) <value>
into the desugaring. The reason for this is that the error messages get a lot nastier to handle from the desugared form, and pnkfelix did not want to hold this work up further trying to resolve that.The final design for this will require an RFC; this code is entirely experimental for now.
Proto RFC: http://discuss.rust-lang.org/t/pre-rfc-placement-box-with-placer-trait/729/5